package com.ddxz.csms.controller;

import com.ddxz.csms.service.DataService;
import com.ddxz.tool.web.dto.DdxzResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2021/11/20
 */

@RestController
public class DataController {
    /**
     * 生成beginDate和endDate直接的运行态势数据
     * @param startDate 开始日期：yyyy-MM-dd格式
     * @param endDate 结束日期：yyyy-MM-dd格式
     * @return 生成的数据汇总情况
     */
    @RequestMapping(value = "/begin", method = RequestMethod.GET)
    public DdxzResponse begin(@RequestParam("start") String startDate, @RequestParam("stop") String endDate) {
        try {
            return service.begin(startDate, endDate);
        } catch (ParseException e) {
            e.printStackTrace();
            return DdxzResponse.correct("ERROR");
        }
    }

    private final DataService service;

    public DataController(DataService service) {
        this.service = service;
    }
}
